//
//  SelectBankController.m
//  MyBank
//
//  Created by 崔宝印 on 2017/8/3.
//  Copyright © 2017年 Koolearn. All rights reserved.
//

#import "SelectBankController.h"
#import "BankCell.h"

@interface SelectBankController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (strong, nonatomic) NSArray *bankArray;
@end

@implementation SelectBankController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.bankArray = [NSMutableArray array];
    
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BankList" ofType:@"plist"];
    self.bankArray = [NSArray arrayWithContentsOfFile:plistPath];
    [self.myTableView reloadData];
}

#pragma mark - IBAction
- (IBAction)goBackAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.bankArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier = @"BankCell";
    BankCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier forIndexPath:indexPath];
    cell.bankLabel.text = self.bankArray[indexPath.row];
    cell.tagImageView.image = [UIImage imageNamed:self.bankArray[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BankSelectFinished" object:self.bankArray[indexPath.row]];
    [self goBackAction:nil];
}
@end
